package com.restaurantonlineorder.oauth.handler;

import com.restaurantonlineorder.oauth.utils.ResponseUtil;
import com.restaurantonlineorder.response.BaseResult;
import com.restaurantonlineorder.response.BaseResultCode;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author 熊宇
 * @date 2022/7/20 23:00
 * @description 权限校验异常处理
 */

@Component
public class OauthAccessDeniedHandler implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
        ResponseUtil.sendMessage(response, BaseResult.failure(BaseResultCode.PERMISSION_NO_ACCESS));
    }
}
